<?php

class Response extends AppModel {
/**
 * Name
 *
 * @var string
 */
 
    public $name = "Response";
    
    public $belongsTo = array(
        'Customer'=>array(
            'className'=>'Customer',
            'foreignKey'=>'customer_id'
        ),
        'Survey'=>array(
            'className'=>'Survey',
            'foreignKey'=>'survey_id'
        )
    );
    public static function count_response($survey_id) {
        $res = ClassRegistry::init("Response");
        $res->unbindModel(array('belongsTo'=>array('Customer','Survey')));
        $surveys = $res->find("count",array('conditions'=>array('survey_id'=>$survey_id)));
        return $surveys;
    }
    public function get_surveys_customer($customer_id){
        $this->unbindModel(array('belongsTo'=>array('Customer','Survey')));
        $surveys = $this->find("all",array('conditions'=>array("customer_id"=>$customer_id)));
        $surs = array();
        if(!empty($surveys)){
            foreach ($surveys as $value) {
                $surs[]=$value['Response']['survey_id'];
            }
        }
        return $surs;
    }
    public function check_survey_customer($survey_id,$customer_id) {
        $this->unbindModel(array('belongsTo'=>array('Customer','Survey')));
        $surveys = $this->find("first",array('conditions'=>array("customer_id"=>$customer_id,'survey_id'=>$survey_id)));
        if(!empty($surveys)){
            return 1;
        }
        return 0;
    }
}